<template>
  <!-- 优秀辅导员名单 -->
  <div class="app-container">
    <el-row :gutter="20">
      <!--教师基本信息-->
      <!-- <el-col :span="4" :xs="5">
        <treeIndex :deptOptions="deptOptions" @handleNode="handleNodeClick" :title="'部门信息'"></treeIndex>
      </el-col> -->
      <el-col :span="24" :xs="24">
        <searchForm
          :formOptions="formOptions"
          @onSearch="onSearch"
          @onReset="onReset"
          :formLabelWidth="formLabelWidth"
          v-show="showSearch"
        />
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['clr:xlntclr:remove']"
            >删除</el-button>
          </el-col>

          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="xlntclrList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="辅导员姓名" align="center" prop="clrName" />
          <el-table-column label="批次名称" align="center" prop="batchName"></el-table-column>
          <el-table-column label="辅导员工号" align="center" prop="clrTno" />
          <el-table-column label="所在院系" align="center" prop="deptName" />
          <el-table-column label="学年" align="center" prop="amcYear" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['clr:xlntclr:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  listXlntclr,
  getXlntclr,
  delXlntclr,
  addXlntclr,
  updateXlntclr
} from "@/api/clr/xlntclr";
import searchForm from "@/components/Search/searchForm.vue";
import { deptTreeSelect } from "@/api/system/user";
// import treeIndex from "@/components/tree/index.vue";
import { getSelector} from "@/api/clr/batch";
import {
  collegeSelect
} from "@/api/information/studentInfor"
export default {
  name: "Xlntclr",
  components: {
    // treeIndex,
    searchForm
  },
  data() {
    return {
      formLabelWidth: "85px",
      formOptions: [
      {
          label: "院系",
          prop: "deptId",
          element: "el-select",
          options: [],
          placeholder: "请选择院系"
        },
        {
          label: "辅导员工号",
          prop: "clrTno",
          element: "el-input",
          placeholder: "请输入辅导员工号"
        },
        {
          label: "辅导员姓名",
          prop: "clrName",
          element: "el-input",
          placeholder: "请输入辅导员姓名"
        },
        {
          label: "学年",
          prop: "amcYears",
          type: "monthrange",
          element: "el-date-picker",
          placeholder: "请选择学年",
          valueFormat: "yyyy-MM"
        },
        {
          label: "批次名称",
          prop: "cebId",
          element: "el-select",
          options: [],
          placeholder: "请输入批次名称"
        },
        // {
        //   label: "考核类型",
        //   prop: "cebType",
        //   element: "el-select",
        //   options: [],
        //   placeholder: "请选择考核类型"
        // }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优秀辅导员推荐表格数据
      xlntclrList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cebId: null,
        cefId: null,
        cId: null,
        deptId: null
      },
      deptOptions: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      names:[],
    };
  },
  created() {
    this.department();
    this.getList();
    getSelector({cebType:'E'}).then(res => {  
      this.formOptions[4].options = res.data.map(item => {
        return {
          value: item["CEBID"],
          label: item["BATCHNAME"]
        };
      });
    })
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      if(val.amcYears) {
        val.startAmcYear = val.amcYears[0];
        val.endAmcYear = val.amcYears[1];
      }
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      data.startAmcYear = undefined
      data.endAmcYear = undefined
      this.queryParams.pageNum = 1;
      this.queryParams.deptId = '';
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    /** 查询优秀辅导员推荐列表 */
    getList() {
      this.loading = true;
      listXlntclr(this.queryParams).then(response => {
        console.log(response, "listXlntclr");
        this.xlntclrList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // tree树形选中的值
    handleNodeClick(data) {
      console.log(data, "选中的值");
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 获取部门信息
    async department() {
      await collegeSelect().then(res => {
        // this.deptOptions = res.data;
        this.formOptions[0].options = res.data.map(item => {
          return {
            value: item.deptId,
            label: item.deptName
          };
        });
      });
    },
  
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cexId);
      this.names = selection.map(item => item.clrName);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加优秀辅导员推荐";
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cexId != null) {
            updateXlntclr(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addXlntclr(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cexIds = row.cexId || this.ids;
      this.names = row.clrName || this.names;
      this.$modal
        .confirm('是否确认删除优秀辅导员"' + this.names + '"的数据项？')
        .then(function() {
          return delXlntclr(cexIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "clr/xlntclr/export",
        {
          ...this.queryParams
        },
        `xlntclr_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
